home *** CD-ROM | disk | FTP | other *** search
- TYPE
- charset = Set of Char;
- FUNCTION get_nth_word(wrkstr : STRING; nth_word : BYTE;
- Delim : charset) : STRING;
- VAR
- i, ndx, start_pt, end_pt : BYTE;
- found : BOOLEAN;
- BEGIN
- start_pt := 1;
- end_pt := length(wrkstr);
- IF LENGTH(wrkstr) = 0 THEN BEGIN
- result := æÆ; { whoops, empty string}
- EXIT;
- END;
- ndx := 1;
- FOR i := 1 TO nth_word DO BEGIN
- found := FALSE;
- REPEAT { find first delimiter }
- IF wrkstr[ndx] in delim THEN
- INC(ndx)
- ELSE BEGIN
- start_pt := ndx;
- found := TRUE;
- END;
- UNTIL found;
- found := FALSE;
- REPEAT { find end of this word }
- IF (ndx > LENGTH(wrkstr)) OR (wrkstr[ndx] in delim)
- THEN BEGIN
- end_pt := ndx - 1;
- found := TRUE;
- END ELSE
- INC(ndx);
- UNTIL found;
- END;
- result := COPY(wrkstr, start_pt, end_pt - start_pt + 1);
- END;
-